package com.sgb.kjwl.view.ui.fragment.transport;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import com.sgb.kjwl.AppLazyFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.AppFrLogisticsDemandBinding;
import com.sgb.kjwl.view.ui.fragment.demandHall.CustomerInquiryFragment;
import com.sgb.kjwl.view.ui.fragment.home.CarrierDemandFragment;
import com.swgk.core.recyclerview.adapter.SlidingFragmentPagerAdapter;

import java.util.ArrayList;

/**
 * Describe:
 * Author:  yangLei
 * Date:    2021/11/19
 */
public class LogisticsDemandFragment extends AppLazyFragment {

    AppFrLogisticsDemandBinding mBinding;
    private final String[] mTabs = new String[]{"货源信息", "承运需求"};
    private SlidingFragmentPagerAdapter mAdapter;
    private String websiteNo;
    private String websiteType;

    public static LogisticsDemandFragment newInstance(String websiteNo,String websiteType) {
        LogisticsDemandFragment fragment = new LogisticsDemandFragment();
        Bundle bundle = new Bundle();
        bundle.putString("type", websiteType);
        bundle.putString("websiteNo", websiteNo);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments()!=null){
            websiteType = getArguments().getString("type");
            websiteNo = getArguments().getString("websiteNo");
        }
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBinding = DataBindingUtil.inflate(inflater, R.layout.app_fr_logistics_demand, container, false);
        return mBinding.getRoot();
    }

    @Override
    protected void onLazyLoad() {
        initFragment();
    }

    private void initFragment() {
        //viewPager适配器
        ArrayList<Fragment> fragments = new ArrayList<>();
        //添加页面
        fragments.add(GoodsFragment.newInstance(websiteType,websiteNo));
        fragments.add(CarrierDemandFragment.newInstance(websiteType,websiteNo));
        mAdapter = new SlidingFragmentPagerAdapter(getChildFragmentManager(), fragments, mTabs);
        mBinding.vpLogisticsDemand.setAdapter(mAdapter);
        mBinding.vpLogisticsDemand.setOffscreenPageLimit(2);
        mBinding.tabLayout.setupWithViewPager(mBinding.vpLogisticsDemand);
    }
}